
* estimate model

*Load Data
use book-basedata-replication, clear
eststo clear


*splitting at failure times
stsplit, at(failures)

*recalculate the interaction with time
foreach var in manip2 nomanip2 prevcris2 viol2 crisdur2 jointdem victory2 contig2 {
replace `var'_t= `var'*_t
}

*rerun final model from main manuscript
eststo, title(restricted): stcox manip2 manip2_t nomanip2 prevcris2 prevcris2_t viol2 crisdur2 jointdem victory2 contig2 if _t<3650, strata(order5) cluster(dyadno) efron nohr

*evaluate proportional hazards assumption 
estat phtest, detail

*add mediator type
eststo, title(restricted): stcox manip2 manip2_t nomanip2 medigo2 medrgo2 medconcert2 nomedgo2 prevcris2 prevcris2_t viol2 crisdur2 jointdem victory2 contig2 if _t<3650, strata(order5) cluster(dyadno) efron nohr

*evaluate proportional hazards assumption 
estat phtest, detail

*distinguish single vs. multiple mediators
eststo, title(restricted): stcox manip2 manip2_t nomanip2 medsolo2 nomedsolo2 prevcris2 prevcris2_t viol2 crisdur2 jointdem victory2 contig2 if _t<3650, strata(order5) cluster(dyadno) efron nohr

*evaluate proportional hazards assumption --> PERFECT
estat phtest, detail


esttab, star(* 0.1 ** 0.05 *** 0.01) b(3) se(3)  mtitle nodepvar  /*
*/ 		order(manip2 manip2_t nomanip2 medigo2 medrgo2 medconcert2 medsolo2) drop(nomed*) noobs /*
*/		scalar("N_sub Cases" "N_fail Failures") /*
*/ 		varlabels(manip2 "Manipulation"/*
*/ 		manip2_t "Manipulation * time"/*
*/		nomanip2 "Other mediation "/*
*/ 		nomanip2_t "Other mediation * time"/*
*/		medigo2 "Global IGO"/*
*/		medrgo2 "RGO"/*
*/		medconcert2 "Concert"/*
*/		medsolo2 "Solo mediation "/*
*/ 		prevcris2 "Previous crises"/*
*/ 		viol2 "Violence level"/*
*/ 		crisdur2 "Crisis duration"/*
*/ 		jointdem "Democratic dyad"/*
*/ 		victory2 "Victory"/*
*/ 		contig2 "Contiguity"/*
*/ 		prevcris2_t "Previous crises * time"/*
*/ 		viol2_t "Violence level * time"/*
*/ 		crisdur2_t "Crisis duration * time"/*
*/ 		jointdem_t "Democratic dyad * time"/*
*/ 		victory2_t "Victory * time"/*
*/ 		contig2_t "Contiguity * time"/*
*/		_cons Constant)
esttab using _table_type.rtf, star(* 0.1 ** 0.05 *** 0.01)  b(3) se(3)  mtitle nodepvar  /*
*/ 		order(manip2 manip2_t nomanip2 medigo2 medrgo2 medconcert2 medsolo2) drop(nomed*) noobs replace /*
*/		scalar("N_sub Cases" "N_fail Failures") /*
*/ 		varlabels(manip2 "Manipulation"/*
*/ 		manip2_t "Manipulation * time"/*
*/		nomanip2 "Other mediation "/*
*/ 		nomanip2_t "Other mediation * time"/*
*/		medigo2 "Global IGO"/*
*/		medrgo2 "RGO"/*
*/		medconcert2 "Concert"/*
*/		medsolo2 "Solo mediation "/*
*/ 		prevcris2 "Previous crises"/*
*/ 		viol2 "Violence level"/*
*/ 		crisdur2 "Crisis duration"/*
*/ 		jointdem "Democratic dyad"/*
*/ 		victory2 "Victory"/*
*/ 		contig2 "Contiguity"/*
*/ 		prevcris2_t "Previous crises * time"/*
*/ 		viol2_t "Violence level * time"/*
*/ 		crisdur2_t "Crisis duration * time"/*
*/ 		jointdem_t "Democratic dyad * time"/*
*/ 		victory2_t "Victory * time"/*
*/ 		contig2_t "Contiguity * time"/*
*/		_cons Constant) nonotes  /*
*/ 		addnotes("cluster robust s.e., * p < 0.1, ** p < 0.05, *** p < 0.01") 
esttab using _table_type.tex, star(* 0.1 ** 0.05 *** 0.01)  b(3) se(3) label  /*
*/ 		replace noobs scalar("N_sub Cases" "N_fail Failures") /*
*/ 		order(manip2 manip2_t nomanip2 medigo2 medrgo2 medconcert2 medsolo2) drop(nomed*) /*
*/ 		varlabels(manip2 "Manipulation"/*
*/ 		manip2_t "Manipulation * time"/*
*/		nomanip2 "Other mediation "/*
*/ 		nomanip2_t "Other mediation * time"/*
*/		medigo2 "Global IGO"/*
*/		medrgo2 "RGO"/*
*/		medconcert2 "Concert"/*
*/		medsolo2 "Solo mediation "/*
*/ 		prevcris2 "Previous crises"/*
*/ 		viol2 "Violence level"/*
*/ 		crisdur2 "Crisis duration"/*
*/ 		jointdem "Democratic dyad"/*
*/ 		victory2 "Victory"/*
*/ 		contig2 "Contiguity"/*
*/ 		prevcris2_t "Previous crises $\times$ time"/*
*/ 		viol2_t "Violence level $\times$ time"/*
*/ 		crisdur2_t "Crisis duration $\times$ time"/*
*/ 		jointdem_t "Democratic dyad $\times$ time"/*
*/ 		victory2_t "Victory $\times$ time"/*
*/ 		contig2_t "Contiguity $\times$ time"/*
*/		_cons Constant)  /*
*/ 		nodepvar mtitle nonotes booktabs /*
*/ 		addnotes("cluster robust s.e., * p \textless 0.1, ** p \textless 0.05, *** p \textless 0.01") 
